package com.jdd.modules.parkcar.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jdd.common.system.vo.LoginUser;
import com.jdd.common.util.SnowFlakeUtil;
import com.jdd.common.util.excel.web.entity.vo.NormalExcelConstants;
import com.jdd.modules.parkWhiteEdit.entity.ParkWhiteEditList;
import com.jdd.modules.parkcar.entity.ParkCarMonthly;
import com.jdd.modules.parkcar.entity.ParkCarStored;
import com.jdd.modules.parkcar.entity.ParkInnerInfo;
import com.jdd.modules.parkcar.entity.ParkWhiteList;
import com.jdd.modules.parkcar.service.IParkCarMonthlyService;
import com.jdd.modules.parkcar.service.IParkInnerListService;
import com.jdd.modules.parkcar.service.IParkWhiteListService;
import com.jdd.modules.storecar.entity.StoreCarList;
import com.jdd.modules.storecar.service.IStoreCarListService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * @author liuyaowen
 */
public class ParkCarUtil {


    /**
     * @Description: 向白名单Excel文件中分页添加数据
     * @author: 刘耀文
     * @Date: 2021-04-07
     * @version 1.0
     * @param mv 导出的白名单Excel文件
     * @param parkCarMonthlyService 月租车服务
     * @param queryWrapper 查询条件
     * @param pageNo 页码
     * @param pageSize 页大小
     */
    public ModelAndView addDataToModelAndView(ModelAndView mv, IParkCarMonthlyService parkCarMonthlyService, QueryWrapper<ParkCarMonthly> queryWrapper, int pageNo, int pageSize) {
        Page<ParkCarMonthly> page = new Page<>(pageNo, pageSize);
        IPage<ParkCarMonthly> iPage = parkCarMonthlyService.page(page, queryWrapper);
        mv.addObject(NormalExcelConstants.DATA_LIST, iPage.getRecords());
        return mv;
    }
    public ModelAndView addDataToModelAndViewStoreCar(ModelAndView mv, IStoreCarListService storeCarListService, QueryWrapper<StoreCarList> queryWrapper, int pageNo, int pageSize) {
        Page<StoreCarList> page = new Page<>(pageNo, pageSize);
        IPage<StoreCarList> iPage = storeCarListService.page(page, queryWrapper);
        mv.addObject(NormalExcelConstants.DATA_LIST, iPage.getRecords());
        return mv;
    }
    public ModelAndView addDataToModelAndViewWhiteCar(ModelAndView mv,IParkWhiteListService parkWhiteListService,QueryWrapper<ParkWhiteList> queryWrapper,int pageNo,int pageSize)
    {
        Page<ParkWhiteList> page = new Page<>(pageNo, pageSize);
        IPage<ParkWhiteList> iPage = parkWhiteListService.page(page, queryWrapper);
        mv.addObject(NormalExcelConstants.DATA_LIST, iPage.getRecords());
        return mv;
    }

    public ParkWhiteEditList getParkWhiteEditList(ParkCarStored parkCarStored) {
        ParkWhiteEditList parkWhiteEditList = new ParkWhiteEditList();
        BeanUtils.copyProperties(parkCarStored, parkWhiteEditList);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        parkWhiteEditList.setId(SnowFlakeUtil.getId());
        parkWhiteEditList.setUpdateUser(sysUser.getUsername());
        parkWhiteEditList.setUpdateTime(new Date());
        return parkWhiteEditList;
    }

    public ModelAndView addDataToModelAndViewInnerCar(ModelAndView mv, IParkInnerListService parkInnerListService, QueryWrapper<ParkInnerInfo> queryWrapper, int pageNo, int pageSize) {
        Page<ParkInnerInfo> page = new Page<>(pageNo, pageSize);
        IPage<ParkInnerInfo> iPage = parkInnerListService.page(page, queryWrapper);
        mv.addObject(NormalExcelConstants.DATA_LIST, iPage.getRecords());
        return mv;
    }
}
